package com.yootk.service.load;

import com.yootk.common.dto.MemberDTO;
import com.yootk.service.IMemberTokenService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class FeignTokenLoaderRunner implements CommandLineRunner {
    @Autowired
    private IMemberTokenService memberTokenService; // 远程接口映射
    @Override
    public void run(String... args) throws Exception {
        MemberDTO dto = new MemberDTO();
        dto.setMid("admin");
        dto.setPassword("hello");
        String token = this.memberTokenService.login(dto); // 获取Token
        if (token != null) {    // 已经获取到了Token数据
            log.info("获取Token数据成功：{}", token);
            System.setProperty("yootk.token", token); // 属性不允许为null
        }
    }
}
